package
{
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	import mx.controls.Menu;
	import mx.controls.MenuBar;
	
	import spark.components.Button;
	import spark.components.HGroup;
	
	public class CustomPopUpMenuButton extends HGroup
	{
		
		private var button:Button;
		public var menuBar:MenuBar;
		public var buttonWidth:int = 20;
		[Bindable]
		public var dataProvider:Object;
		[Bindable]
		public var labelField:String;
		
		public function CustomPopUpMenuButton()
		{
			button = new Button();
			button.width = buttonWidth
			button.percentHeight = 100;
			button.addEventListener(MouseEvent.CLICK, popUpMenuButtonClick);
			
			menuBar = new MenuBar();
			menuBar.percentWidth = 100;
			menuBar.percentHeight = 100;
			
			this.addElement(menuBar);
			this.addElement(button);
			menuBar.dataProvider = dataProvider;
			menuBar.labelField = labelField;
			super();
		}
		
		public function popUpMenuButtonClick(e:MouseEvent):void
		{
			var menu:Menu = menuBar.getMenuAt(0);
			var point:Point = new Point(menuBar.x,menuBar.y + menuBar.height);
			point = localToGlobal(point);
			menu.show(point.x,point.y);
		}
	}
}